home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / basicsub.doc < prev    next >
Text File  |  1983-10-31  |  4KB  |  77 lines

  1.  
  2.                    --------------------------------
  3.                        THE CALL STATEMENT
  4.                 --------------------------------
  5.  
  6. There  have  been a number of requests for clarification of the CALL statement
  7. in the various Microsoft langauges.   Hopefully,  the  following  explanations
  8. will  clear up several misunderstandings.  First, let's look at the "Microsoft
  9. call standard".  When any Microsoft program issues a CALL statement,  such  as
  10. "CALL  MYROUT",  control is passed to the address specified by MYROUT.  In all
  11. cases except the BASIC interpreter, MYROUT must be the name  of  a  subroutine
  12. program,  or a global/public label within a MACRO-80 routine.  The calling and
  13. the called program must be linked together by L80 into a single file.  In  the
  14. BASIC  interpreter  (MBASIC), the variable MYROUT must be set to the beginning
  15. address of the subroutine.  
  16.  
  17. If we complicate things by adding a few paramaters to the CALL, such as: "CALL
  18. MYROUT(A,B); the parameters are passed as follows:  The *ADDRESS* of the first
  19. parameter  is  passed  in registers HL, the second in DE, and the third in BC.
  20. If there are more than three parameters,  BC  points  to  a  block  of  memory
  21. containing the *ADDRESS* of parameters three through N.  Note that the address
  22. and *NOT* the parameter itself is passed.  The arguments themselves correspond
  23. to  the  standard  MICROSOFT variable format, (2 bytes for an integer, 4 bytes
  24. for single precision floating point,  and  8  bytes  for  a  double  precision
  25. floating  point  number)  with two exceptions.  
  26.  
  27. COBOL passes variables as they would appear to another COBOL program (display,
  28. comp,  or  comp-3).   Strings are also handled a bit differently.  The address
  29. pointed to by the register contains a three byte  "string  descriptor".   This
  30. string  descriptor  contains  the  length  of  the string in byte one, and the
  31. address of the string in bytes two and three.  When passing strings, take care
  32. not to modify this string descriptor, or unpredictable results will occur.  
  33.  
  34. In  all  cases,  it  is the user's responsibility to ensure that the arguments
  35. correspond *exactly*, in both type and number.   Also,  be  sure  to  preserve
  36. *all*  of  the  registers  and  use  your  own local stack when you call macro
  37. routines.  
  38.  
  39. With  the preliminaries out of the way, let's look at which languages can call
  40. which other languages.  In the  following  table,  "B"  represents  the  BASIC
  41. interpreter  (MBASIC),  "BC"  the  BASIC  Compiler  (BASCOM),  "F" the FORTRAN
  42. Compiler (F80), "C" the COBOL Compiler, and "M" the MACRO Assembler (M80).   A
  43. "Y" in the appropriate entry means that a CALL is possible.
  44.  
  45.         CALLED PROGRAM
  46. ********************************
  47. CALLING* **   **    **     **
  48. PROGRAM*B** BC**  F **  C  ** M
  49. ********************************
  50. B      * **   **    **     ** Y
  51. ********************************
  52. BC     * **   **  1 **     ** Y
  53. ********************************
  54. F      * **   **  Y **     ** Y
  55. ********************************
  56. C      * **   **  2 **  Y  ** Y
  57. ********************************
  58. M      * **   **  3 **     ** Y
  59. ********************************
  60.  
  61.     [NOTES:]
  62.  
  63. 1  -  When  calling a FORTRAN routine from the BASIC Compiler, only one of the
  64. two languages may be used to perform I/O.  When the programs are linked,  LINK
  65. the  BASIC  program  first, then search BASLIB, then load the FORTRAN program,
  66. then search FORLIB.  The multiply defined global message may be ignored.  
  67.  
  68. 2  -  When  calling  FORTRAN  from COBOL, remember that the variable types are
  69. different.  Only comp data items will be passed in such a way that FORTRAN can
  70. deal with them without an encode statement.  
  71.  
  72. 3 - While MACRO-80 may not directly call FORTRAN subroutines, you may make use
  73. of  the routines in the FORTRAN library.  For more information,see the FORTRAN
  74. manual.  Of course, from within M80, you may initiate execution of  any  other
  75. .COM file by reading the file and then jumping to the appropriate address.
  76. in M80, you may initiate execution of  any  other
  77. .COM file by readin